<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<SCRIPT TYPE="text/javascript">
<!--
function refresh() {
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
	}
	else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	var html = "<table class='files' id='files'>"
		+ "<tr><th colspan='4'><fmt:message key="table.header"/></th><tr>"
		+ "<tr>"
		+ "<th align='left'><fmt:message key="table.name"/></th>"
		+ "<th align='center'><fmt:message key="table.size"/></th>"
		+ "<th align='center'><fmt:message key="table.modified"/></th>"
		+ "<th align='center'><button onclick=\"refresh()\"><fmt:message key="table.refresh"/></button></th>"
		+ "</tr>";

	xmlhttp.open("GET","upload",false);
	xmlhttp.send();
	xmlDoc=xmlhttp.responseXML; 

	var x=xmlDoc.getElementsByTagName("file");
	var name;
	for (i=0;i<x.length;i++) { 
		name=x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
		html = html 
		+ "<tr><td>"
		+ "<a href='upload?file=" +name +"''>" +name
		+ "</td><td align='right'>"
		+ x[i].getElementsByTagName("size")[0].childNodes[0].nodeValue
		+ "</td><td align='right'>"
		+ x[i].getElementsByTagName("modified")[0].childNodes[0].nodeValue
		+ "</td><td align='center'>"
		+ "<button onclick=\"deletefile('" +name +"')\"><fmt:message key="table.delete"/></button>"
		+ "</td></tr>";
	}
	html = html + "</table>";
	document.getElementById('tablediv').innerHTML = html;
}

function deletefile(name) {
	var del = confirm("Are you sure you want to delete '" +name +"' ?");
	if (del) {
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else {// code for IE6, IE5
	  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.open("DELETE","upload?file=" +name,false);
		xmlhttp.send();
		refresh();
	}
}
//-->
</SCRIPT>

<div>
<APPLET CODE="jfileupload.upload.client.MApplet.class" JAVA_CODEBASE="./" ARCHIVE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar" WIDTH="100%" HEIGHT="200" NAME="fileupload">
<PARAM NAME=CODE VALUE="jfileupload.upload.client.MApplet.class">
<PARAM NAME=CODEBASE VALUE="./">
<PARAM NAME=ARCHIVE VALUE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar">
<PARAM NAME=NAME VALUE="fileupload">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">
<PARAM NAME="scriptable" VALUE="true">
<PARAM NAME="url" VALUE="http://localhost:8080/sanger/upload">
<!--  <PARAM NAME="url" VALUE="http://netsoc.com:9080/sanger/upload"> -->
<PARAM NAME="paramfile" VALUE="uploadfile">
<PARAM NAME="param1" VALUE="account">
<PARAM NAME="value1" VALUE=<sec:authentication property="principal.username"/>>
<PARAM NAME="mode" VALUE="http">'
</APPLET>
</div>
<div id="tablediv"/>

<script type="text/javascript">
<!--
refresh();
//-->
</script>